//
//  Paging.m
//  Pagination
//
//  Created by XMac on 2018/11/15.
//  Copyright © 2018 XMac. All rights reserved.
//



#import "Paging.h"


@interface Paging ()

@property (assign, nonatomic) int defaultPage;

@property (assign, nonatomic) int defaultSize;

@property (strong, nonatomic) id<PagingProcess> process;

@end

@implementation Paging

-(instancetype)initWithDefaultPage:(int)page withDefaultSize:(int)size withProcess:(id<PagingProcess>)process
{
    self = [super init];
    if (self) {
        self.defaultPage = page;
        self.defaultSize = size;
        self.process = process;
        self.process.page = self.defaultPage;
        self.process.size = self.defaultSize;
    }
    return self;
}

-(void)reset{
    [self.process reset:self.defaultPage];
}

-(int)nextPage{
    return self.process.page;
}

-(int)pageSize{
    return self.process.size;
}


//这里要返回block的句柄,以供afn去回调
-(id)getProcessSuccess{
    if (!self.process) {
        return nil;
    }
    return self.process.getProcessSuccess;
}

-(id)getProcessFailure{
    if (!self.process) {
        return nil;
    }
    return self.process.getProcessFailure;
}



@end
